using UnityEngine;

namespace ZSW.Framework.InputSystem
{
    public enum ZSWFEMouseButton
    {
        Left = 0,
        Right = 1,
        Middle = 2,
    }

    public class ZSWF_InputSystem : ZSWF_Singleton<ZSWF_InputSystem>
    {
        #region 鼠标事件

        /// <summary>
        /// 获取鼠标位置
        /// </summary>
        /// <returns></returns>
        public Vector2 GetMousePosition()
        {
            return Input.mousePosition;
        }

        /// <summary>
        /// 获取鼠标滚轮的滚动值
        /// </summary>
        /// <returns></returns>
        public float GetMouseScroll()
        {
            return Input.GetAxis("Mouse ScrollWheel");
        }

        /// <summary>
        /// 获取鼠标的移动方向
        /// </summary>
        /// <returns></returns>
        public Vector2 GetMouseDirection()
        {
            Vector2 vec = GetMouseVelocity();
            return vec.normalized;
        }

        /// <summary>
        /// 获取鼠标的移动方向和速度
        /// </summary>
        /// <returns></returns>
        public Vector2 GetMouseVelocity()
        {
            float x = Input.GetAxis("Mouse X");
            float y = Input.GetAxis("Mouse Y");
            return new Vector2(x, y);
        }

        /// <summary>
        /// 以屏幕中心为原点，获取鼠标的百分比位置（-0.5~0.5）
        /// </summary>
        /// <returns></returns>
        public Vector2 GetRelativeMouseMovement()
        {
            float x = GetMousePosition().x;
            float y = GetMousePosition().y;
            return new Vector2(x / Screen.width - 0.5f, y / Screen.height - 0.5f);
        }

        public Vector2 Shake()
        {
            return GetMouseDirection();
        }

        /// <summary>
        /// 鼠标是否按下
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        public bool GetMouseButtonDown(ZSWFEMouseButton button)
        {
            return Input.GetMouseButtonDown((int)button);
        }

        /// <summary>
        /// 鼠标是否激活中
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        public bool GetMouseButton(ZSWFEMouseButton button)
        {
            return Input.GetMouseButton((int)button);
        }

        /// <summary>
        /// 鼠标是否抬起
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        public bool GetMouseButtonUp(ZSWFEMouseButton button)
        {
            return Input.GetMouseButtonUp((int)button);
        }
        #endregion


        #region 键盘事件

        public bool GetAcceleration()
        {
            return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        }

        public bool GetDirectionAndSpeed(out Vector2 direction)
        {
            float horizontal = Input.GetAxis("Horizontal");
            float vertical = Input.GetAxis("Vertical");
            direction = new Vector2(horizontal, vertical);
            return horizontal != 0 || vertical != 0;
        }

        public bool GetHeightDelta(out float height)
        {
            height = 0;
            // 检查Z键是否被按下
            if (Input.GetKey(KeyCode.Z))
            {
                height += UnityEngine.Time.deltaTime;
            }

            // 检查C键是否被按下
            if (Input.GetKey(KeyCode.C))
            {
                height -= UnityEngine.Time.deltaTime;
            }

            return height != 0;
        }
        #endregion

    }
}